package thread;

import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.junit.Test;

/**
 * @author 宫新程
 * @since 2018/12/23 3:22 PM
 */
public class Test_Thread {

  @Test
  public void test1() throws Exception {
    List<Future<String>> listString = new LinkedList<>();
    ExecutorService pool = Executors.newFixedThreadPool(20);
    for (int i = 0; i < 10; i++) {
      Future<String> submit =
          pool.submit(
              () -> {
                int sum = 0;
                for (int y = 1; y <= 10; y++) {
                  sum += y;
                }
                return Thread.currentThread().getName() + "：" + sum;
              });
      listString.add(submit);
    }
    pool.shutdown();

    listString.forEach(
        e -> {
          try {
            System.out.println(e.get());
          } catch (Exception ee) {
            ee.printStackTrace();
          }
        });
  }
}
